﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using YEngineLib;
using YEngineLib.Animation;

namespace Spyfall.Objects
{
    class Coins : Object
    {
        public Texture2D texture;
        public Vector2 position;
        public Vector2 velocity;
        List<Animation> obstacleAnimationList;
        Animation idleAnimation;

        public Coins()
        {
            ObjectID = Object_Type.COINS;
        }

        public void Initialize(Texture2D pTexture, float pPositionX, float pPositionY, float pVelocityX, float pVelocityY)
        {
            obstacleAnimationList = new List<Animation>();
            idleAnimation = new Animation();
            texture = pTexture;

            Random rand = new Random();
            if (rand.Next(1, 100) >= 50)
            {
                position.X = pPositionX;
                position.Y = pPositionY;
                velocity.X = pVelocityX*2;
                velocity.Y = pVelocityY;
                //idleAnimation.Initialize(texture, position, 117, 117, 2, 0.2f, Color.White, 1, true);
            }
            else
            {
                position.X = 1280;                  //1280x720
                position.Y = pPositionY;
                velocity.X = -pVelocityX *2;
                velocity.Y = pVelocityY;
                //idleAnimation.Initialize(texture, position, 117, 117, 2, 0.2f, Color.White, 1, true);
            }

            //obstacleAnimationList.Add(idleAnimation);
            ColRect = new Rectangle((int)position.X, (int)position.Y, this.texture.Width / 2, this.texture.Height);
        }

        public override void Update(float deltaTime)
        {
            //// Animation Stuff Start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            //for (int i = obstacleAnimationList.Count - 1; i >= 0; i--)
            //{
            //    obstacleAnimationList[i].Update(deltaTime);
            //    //MOVEMENT
            //    obstacleAnimationList[i].Position.X += (velocity.X * deltaTime);
            //    obstacleAnimationList[i].Position.Y += (velocity.Y * deltaTime);

            //    if (obstacleAnimationList[i].Active == false)
            //    {
            //        obstacleAnimationList.RemoveAt(i);
            //    }
            //}
            //// Animation Stuff End   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            position.Y += (velocity.Y * deltaTime);
            position.X += (velocity.X * deltaTime);
            //may need to adjust collition rect
            ColRect = new Rectangle((int)position.X, (int)position.Y, this.texture.Width, this.texture.Height);
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            //// Animation Stuff Start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            //for (int i = 0; i < obstacleAnimationList.Count; i++)
            //{
            //    obstacleAnimationList[i].Draw(spriteBatch);
            //}
            //// Animation Stuff End   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            YEngine.Graphics.SpriteBatch.Draw(texture, position, Color.White);

            // draw collision rects
            Texture2D dummyTexture;
            Rectangle dummyRectangle;
            dummyRectangle = this.ColRect;
            dummyTexture = new Texture2D(YEngine.Game.GraphicsDevice, 1, 1);
            dummyTexture.SetData(new Color[] { Color.White });

            //YEngine.Graphics.SpriteBatch.Draw(dummyTexture, dummyRectangle, Color.White);
        }

        public override bool Collide(Object tar)
        {
            bool res = ColRect.Intersects(tar.ColRect);
            return res;
        }
    }
}
